#include "csvReader.h"
#include "csvWriter.h"
#include "stdio.h"
int main()
{
    FILE *fp1 = NULL, *fp2 = NULL;
    CsvReader reader = NULL;
    CsvRecord record = NULL;
    CsvWriter writer = NULL;
    CCSVWriteError error = CCSVWriteErrorWriterNoError;

    int i = 0;
    fp1 = fopen("test.csv", "r");
    if (fp1 == NULL)
    {
        return -1;
    }
    fp2 = fopen("testWrite.csv", "w");
    printf("fp2: %p\n", fp2);
    if (fp2 == NULL)
    {
        return -1;
    }

    reader = NewCCSVReader(fp1);
    if (reader == NULL)
    {
        printf("read error: %d\n", reader->error);
        return -1;
    }
    writer = NewCCSVWriter(fp2);
    printf("writer: %p\n", writer);
    if (writer == NULL)
    {
        printf("write error: %d\n", reader->error);
        return -1;
    }
    UseCRLF(writer);

    while (record = CCSVRead(reader))
    {
        for (i = 0; i < record->num; i++)
        {
            printf("%d: %s\n", i, record->elements[i]);
        }
        error = CCSVWrite(writer, record);
        if (error)
        {
            printf("write error: %d\n", error);
        }
    }
    ReleaseCCSVReader(reader);
    fclose(fp1);

    ReleaseCCSVWriter(writer);
    fclose(fp2);

    return 0;
}